import {createRouter, createWebHashHistory} from "vue-router";
import store from "../store";
import {
    CalendarClearOutline,
    CalendarNumberOutline,
    HourglassOutline,
    NewspaperOutline,
    PeopleOutline,
} from "@vicons/ionicons5";

const router = createRouter({
    history: createWebHashHistory(),
    routes: [
        {
            path: "/login",
            name: "Login",
            component: () => import("../components/login/index.vue")
        },
        {
            path: "/",
            name: "Layout",
            component: () => import("../components/layout/index.vue"),
            children: [
                {
                    path: "/metaData",
                    name: "MetaData",
                    component: () => import("../views/MetaData.vue"),
                    meta: {
                        title: "任务配置",
                        icon: CalendarClearOutline
                    }
                },
                {
                    path: "/running",
                    name: "Running",
                    component: () => import("../views/Running.vue"),
                    meta: {
                        title: "执行进度",
                        icon: HourglassOutline
                    }
                },
                {
                    path: "/scheduleLog",
                    name: "ScheduleLog",
                    component: () => import("../views/ScheduleLog.vue"),
                    meta: {
                        title: "调度日志",
                        icon: NewspaperOutline
                    }
                },
                {
                    path: "/user",
                    name: "User",
                    component: () => import("../views/User.vue"),
                    meta: {
                        title: "用户管理",
                        icon: PeopleOutline
                    }
                },
            ]
        },
    ]
});
router.beforeEach( async (to, from, next) => {
    if (to.path === "/login") {
        next();
    } else {
        const token: string = store().token;
        if (token) {
            next();
        } else {
            next("/login");
        }
    }
});
export default router;